package com.slicktechnologies.server;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.google.appengine.api.blobstore.BlobKey;
import com.google.appengine.api.blobstore.BlobstoreService;
import com.google.appengine.api.blobstore.BlobstoreServiceFactory;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.simplesoftwares.client.library.libservice.BlobService;
import com.slicktechnologies.shared.common.helperlayer.DocumentUpload;



@SuppressWarnings("serial")
public class BlobServiceImpl extends RemoteServiceServlet implements BlobService{

	
	BlobstoreService blobstoreservice=BlobstoreServiceFactory.getBlobstoreService();
	
	
	
	
	@Override
	public String getBlobStoreUploadUrl() {
		
		String url=blobstoreservice.createUploadUrl("/slick_erp/uploadservice");
		System.out.println("Created URL IS ---"+url);
		return url;
	}

	@Override
	public DocumentUpload getDocument(String id) {
		
		
	    return null;
	}
	
	 @Override
	  protected void doGet(HttpServletRequest req, HttpServletResponse resp)
	      throws ServletException, IOException {
		    BlobKey blobKey = new BlobKey(req.getParameter("blob-key"));
		    String filename=req.getParameter("filename");
		    resp.setHeader("Content-Disposition", "Attachment;filename="+filename);
		    System.out.println("Ajay---");
	        blobstoreservice.serve(blobKey, resp);
	        

	  }


}
